package logic

import (
	"baidu/modil/mysql"
	"context"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SellListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSellListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SellListLogic {
	return &SellListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SellListLogic) SellList(in *baidurpc.SellListRequest) (*baidurpc.SellListResponse, error) {
	// todo: add your logic here and delete this line
	var sell []mysql.Sell
	mysql.DB.Debug().Find(&sell)
	var sellList []*baidurpc.SellList
	for _, v := range sell {
		list := baidurpc.SellList{
			BookId: int64(v.BookId),
			Text:   v.Text,
		}
		sellList = append(sellList, &list)
	}
	mysql.DB.Debug().Find(&sellList)
	return &baidurpc.SellListResponse{
		List: sellList,
	}, nil
}
